package com.example.springboot_carlos;

import com.example.springboot_carlos.Util.DBUtil;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class CreateDataBase {
    public static void main(String[] args) {
        try {
            create();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
    private static void create() throws SQLException {
        Connection connection = DBUtil.getConnection();
        String sql = "CREATE DATABASE springbootdb";
        Statement statement = connection.createStatement();
        statement.execute(sql);
        sql="USE springbootdb";
        statement.execute(sql);
        sql="CREATE TABLE test(" +
                "id INT PRIMARY KEY AUTO_INCREMENT," +
                "username VARCHAR (30)," +
                "password VARCHAR (30)," +
                "nickname VARCHAR (30)," +
                "age INT(3))";
        statement.execute(sql);
        sql="CREATE TABLE articletest(" +
                "id INT PRIMARY KEY AUTO_INCREMENT," +
                "title VARCHAR (30)," +
                "author VARCHAR (30)," +
                "content VARCHAR (3000)";
        statement.execute(sql);
        sql="CREATE TABLE userinfo(" +
                "id INT PRIMARY KEY AUTO_INCREMENT," +
                "username VARCHAR (30)," +
                "password VARCHAR (30)," +
                "nickname VARCHAR (30)," +
                "age INT(3))";
        statement.execute(sql);
        sql="CREATE TABLE article(" +
                "id INT PRIMARY KEY AUTO_INCREMENT," +
                "title VARCHAR (30)," +
                "author VARCHAR (30)," +
                "content VARCHAR (3000)";
        statement.execute(sql);
        connection.close();

    }
}
